package com.example.principle.beanlife;

import com.example.principle.scope.Dog;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.BeanNameAware;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;

@Slf4j
@Component
public class BeanLifeComponent implements BeanNameAware {

    private UserController userController;

    public BeanLifeComponent() {
        log.info("执行构造函数...");
    }

    @Autowired
    public void setUserController(UserController userController) {
        this.userController = userController;
        log.info("执行setter方法...");
    }

    /**
     * 属性注入之后执行的初始化，可能从配置文件中来
     */
    @PostConstruct
    public void init() {
        log.info("执行init方法...");
    }

    public void use() {
        log.info("执行use方法...");
    }

    @PreDestroy // 在销毁执行执行
    public void destroy() {
        log.info("执行destroy方法...");
    }

    @Override
    public void setBeanName(String s) {
        log.info("执行setBeanName方法" + s);
    }
}
